package cn.admin.controller;

import cn.admin.config.key.RequestKey;
import cn.admin.config.key.StatusCode;
import cn.admin.entity.PaymentRecord;
import cn.admin.service.PaymentRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author: 毛苏宇
 * @Description: You can do it!
 * @Date: Create in 11:32 2019/3/26
 */
@Controller
@RequestMapping("/paymentInfo")
public class PaymentInformationController {

    @Autowired
    private PaymentRecordService paymentRecordService;


    @RequestMapping("/listInfo")
    public String getPaymentRecordAll(HttpServletRequest request) {
        List<PaymentRecord> all = paymentRecordService.getAll();
        request.setAttribute(RequestKey.REQUEST_PAYMENT_INFORMATION, all);
        return "/payInformation";
    }

    @RequestMapping("/modifyPayStatus")
    @ResponseBody
    public String modifyPayStatus(@RequestParam int user_id, @RequestParam int status, @RequestParam int re_id) {
        System.out.println("用户ID:" + user_id + "\t状态:" + status + "\tre:" + re_id);
        boolean b = paymentRecordService.modifyStatus(user_id, re_id, status);
        if (b) {
            return StatusCode.STATUS_SUCCESS;
        } else {
            return StatusCode.STATUS_FAIL;
        }
    }

}
